define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'classes/school/index',
                    add_url: 'classes/school/add',
                    edit_url: 'classes/school/edit',
                    del_url: 'classes/school/del',
                    multi_url: 'classes/school/multi',
                    dragsort_url: '',
                    table: 'classes_school',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortOrder: 'asc',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'school_name', sortable: true, title: __('School_name')},
                        {field: 'province.name', sortable: true, title: __('省份')},
                        {field: 'city.name', sortable: true, title: __('市')},
                        {field: 'district.name', sortable: true, title: __('区')},
                        {field: 'contact_name', sortable: true, title: __('Contact_name')},
                        {field: 'contact_mobile', sortable: true, title: __('Contact_mobile')},
                        {field: 'tiku.name', sortable: true, title: __('题库设置')},
                        {field: 'contact_role', sortable: true, title: __('Contact_role')},
                        {field: 'classes_review', sortable: true, title: __('Classes_review'),searchList: {"0": __('不审核'), "1": __('审核')},formatter: function(value, row, index){
                            return value == 0 ? '不审核' : '审核'
                        }},
                        {
                            field: 'buttons',title: __('Admin'), table: table,
                            buttons: [{
                                name: 'admin',
                                text: __('Admin'),
                                classname: 'btn btn-xs btn-success btn-dialog',
                                title: function (row) { return row.school_name + '管理员'; },
                                icon: 'fa fa-eye',
                                url: 'classes/school/admin?school_id={ids}'
                            }],
                            formatter: Table.api.formatter.buttons
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
                search: true,
                commonSearch: true
            });
            
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        admin: function () {
            

            // 为表格绑定事件
            Controller.api.bindevent();
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});